package org.example.onetry.servlet;

import jakarta.servlet.GenericServlet;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;


import java.io.IOException;
import java.util.List;

@WebServlet (urlPatterns = {"/servi"})
public class servi extends GenericServlet {
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        /**response.setContentType("text/html");
        request.setCharacterEncoding("UTF-8");
         **/
String selct = request.getParameter("select");
        String name = request.getParameter("name");
        System.out.println(selct);
//接收参数时强转为整形
       // Integer selctd = Integer.valueOf(request.getParameter("select"));
/**
 * 返回字符串数组，返回name一样的选项（下拉表单、复选框）的值
        String[] langtype = request.getParameterValues("langtype");
        if (langtype != null) {
            for (String lang : langtype) {
                out.println(lang + "<br>");
            }
        }
 **/

if(selct.equals("1")) {
    HttpSession session = request.getSession();
    session.setAttribute("selct", selct);
    response.sendRedirect("cx");
}else if(selct.equals("2")) {
    //使用session保存传递数据
    HttpSession session = request.getSession();
    session.setAttribute("selct", selct);
    response.sendRedirect("cx");
}else  if (selct.equals("3")) {


    request.getRequestDispatcher("mx").forward(request, response);
}else {
    response.sendRedirect("index.html");
}

    }
}
